﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;

namespace 无线打分网站
{
     [Serializable]
     public class ExperimentData
     {

         public const string IDField ="@ID";

         public const string PRIMARYKEY_Field=@"ID";

         public const string NAMEField ="@Name";

         public const string ROOMField ="@Room";

         public const string TIMESField ="@Times";

         public const string WEEK1Field ="@Week1";

         public const string WEEK2Field ="@Week2";

         public const string WEEK3Field ="@Week3";

         public const string WEEK4Field ="@Week4";

         public const string WEEK5Field ="@Week5";

         public const string WEEK6Field ="@Week6";

         public const string WEEK7Field ="@Week7";

         private Guid _ID;

         private String _Name;

         private String _Room;

         private String _Times;

         private Boolean _Week1;

         private Boolean _Week2;

         private Boolean _Week3;

         private Boolean _Week4;

         private Boolean _Week5;

         private Boolean _Week6;

         private Boolean _Week7;

         public Guid ID
         {
             get{ return _ID;}
             set{ _ID=value;}
         }
         public String Name
         {
             get{ return _Name;}
             set{ _Name=value;}
         }
         public String Room
         {
             get{ return _Room;}
             set{ _Room=value;}
         }
         public String Times
         {
             get{ return _Times;}
             set{ _Times=value;}
         }
         public Boolean Week1
         {
             get{ return _Week1;}
             set{ _Week1=value;}
         }
         public Boolean Week2
         {
             get{ return _Week2;}
             set{ _Week2=value;}
         }
         public Boolean Week3
         {
             get{ return _Week3;}
             set{ _Week3=value;}
         }
         public Boolean Week4
         {
             get{ return _Week4;}
             set{ _Week4=value;}
         }
         public Boolean Week5
         {
             get{ return _Week5;}
             set{ _Week5=value;}
         }
         public Boolean Week6
         {
             get{ return _Week6;}
             set{ _Week6=value;}
         }
         public Boolean Week7
         {
             get{ return _Week7;}
             set{ _Week7=value;}
         }
         public ExperimentData()
         {
             _ID=Guid.Empty;
             _Name="";
             _Room="";
             _Times="";
             _Week1=false;
             _Week2=false;
             _Week3=false;
             _Week4=false;
             _Week5=false;
             _Week6=false;
             _Week7=false;
         }
     }

     public class ExperimentDataFactory
     {
         public static ExperimentData Construct(IDataReader reader)
         {
             ExperimentData data = new ExperimentData();

             try{  data.ID = (Guid)(reader["ID"]) ;} catch { } 

             try{  data.Name = Convert.ToString(reader["Name"])  ;} catch { } 

             try{  data.Room = Convert.ToString(reader["Room"])  ;} catch { } 

             try{  data.Times = Convert.ToString(reader["Times"])  ;} catch { } 

             try{  data.Week1 = Convert.ToBoolean(reader["Week1"])  ;} catch { } 

             try{  data.Week2 = Convert.ToBoolean(reader["Week2"])  ;} catch { } 

             try{  data.Week3 = Convert.ToBoolean(reader["Week3"])  ;} catch { } 

             try{  data.Week4 = Convert.ToBoolean(reader["Week4"])  ;} catch { } 

             try{  data.Week5 = Convert.ToBoolean(reader["Week5"])  ;} catch { } 

             try{  data.Week6 = Convert.ToBoolean(reader["Week6"])  ;} catch { } 

             try{  data.Week7 = Convert.ToBoolean(reader["Week7"])  ;} catch { } 

             return data;
         }
         public static Guid GetPrimaryKey(DataTable dt)
         {
             return GetPrimaryKey(dt,0);
         }
         public static Guid GetPrimaryKey(DataTable dt,int rowIndex)
         {
             Guid PrimaryKey=Guid.Empty;

             if(dt.Rows.Count<rowIndex+1)

                 return Guid.Empty;

             DataRow dr=dt.Rows[rowIndex];

             if(dr==null)

                 return Guid.Empty;

             try{ PrimaryKey = (Guid)(dr[ExperimentData.PRIMARYKEY_Field]) ;} catch { } 

             return PrimaryKey;
         }
         public static ExperimentData Construct(DataTable dt)
         {
             return Construct(dt,0);
         }
         public static ExperimentData Construct(DataTable dt,int rowIndex)
         {
             ExperimentData data = new ExperimentData();

             if(dt.Rows.Count<rowIndex+1)

                 return null;

             DataRow dr=dt.Rows[rowIndex];

             if(dr==null)

                 return null;

             try{ data.ID = new Guid(dr["ID"].ToString()) ;} catch { } 

             try{ data.Name = Convert.ToString(dr["Name"]) ;} catch { } 

             try{ data.Room = Convert.ToString(dr["Room"]) ;} catch { } 

             try{ data.Times = Convert.ToString(dr["Times"]) ;} catch { } 

             try{ data.Week1 = Convert.ToBoolean(dr["Week1"]) ;} catch { } 

             try{ data.Week2 = Convert.ToBoolean(dr["Week2"]) ;} catch { } 

             try{ data.Week3 = Convert.ToBoolean(dr["Week3"]) ;} catch { } 

             try{ data.Week4 = Convert.ToBoolean(dr["Week4"]) ;} catch { } 

             try{ data.Week5 = Convert.ToBoolean(dr["Week5"]) ;} catch { } 

             try{ data.Week6 = Convert.ToBoolean(dr["Week6"]) ;} catch { } 

             try{ data.Week7 = Convert.ToBoolean(dr["Week7"]) ;} catch { } 

             return data;
         }
         public static ExperimentData Construct(DataRow dr)
         {
             ExperimentData data = new ExperimentData();

             try{ data.ID = new Guid(dr["ID"].ToString()) ;} catch { } 

             try{ data.Name = Convert.ToString(dr["Name"]) ;} catch { } 

             try{ data.Room = Convert.ToString(dr["Room"]) ;} catch { } 

             try{ data.Times = Convert.ToString(dr["Times"]) ;} catch { } 

             try{ data.Week1 = Convert.ToBoolean(dr["Week1"]) ;} catch { } 

             try{ data.Week2 = Convert.ToBoolean(dr["Week2"]) ;} catch { } 

             try{ data.Week3 = Convert.ToBoolean(dr["Week3"]) ;} catch { } 

             try{ data.Week4 = Convert.ToBoolean(dr["Week4"]) ;} catch { } 

             try{ data.Week5 = Convert.ToBoolean(dr["Week5"]) ;} catch { } 

             try{ data.Week6 = Convert.ToBoolean(dr["Week6"]) ;} catch { } 

             try{ data.Week7 = Convert.ToBoolean(dr["Week7"]) ;} catch { } 

             return data;
         }
         public static Guid GetPrimaryKey(DataRow dr)
         {
             Guid PrimaryKey=Guid.Empty;

             try{ PrimaryKey = (Guid)(dr[ExperimentData.PRIMARYKEY_Field]) ;} catch { } 
                 return PrimaryKey;
         }

     }
     public class ExperimentDataDBOption
     {
         public static int Insert(ExperimentData d)
         {
             StringBuilder sql=new StringBuilder();
             sql.Append("insert into Experiment (");
             sql.Append("Name, ");
             sql.Append("Room, ");
             sql.Append("Times, ");
             sql.Append("Week1, ");
             sql.Append("Week2, ");
             sql.Append("Week3, ");
             sql.Append("Week4, ");
             sql.Append("Week5, ");
             sql.Append("Week6, ");
             sql.Append("Week7");
             sql.Append(") values (");
             sql.Append("'");
             sql.Append(d.Name.ToString());
             sql.Append("'");
             sql.Append(", ");
             sql.Append("'");
             sql.Append(d.Room.ToString());
             sql.Append("'");
             sql.Append(", ");
             sql.Append("'");
             sql.Append(d.Times.ToString());
             sql.Append("'");
             sql.Append(", ");
             sql.Append("");
             if(d.Week1)
                 sql.Append("1");
             else
                 sql.Append("0");
             sql.Append("");
             sql.Append(", ");
             sql.Append("");
             if(d.Week2)
                 sql.Append("1");
             else
                 sql.Append("0");
             sql.Append("");
             sql.Append(", ");
             sql.Append("");
             if(d.Week3)
                 sql.Append("1");
             else
                 sql.Append("0");
             sql.Append("");
             sql.Append(", ");
             sql.Append("");
             if(d.Week4)
                 sql.Append("1");
             else
                 sql.Append("0");
             sql.Append("");
             sql.Append(", ");
             sql.Append("");
             if(d.Week5)
                 sql.Append("1");
             else
                 sql.Append("0");
             sql.Append("");
             sql.Append(", ");
             sql.Append("");
             if(d.Week6)
                 sql.Append("1");
             else
                 sql.Append("0");
             sql.Append("");
             sql.Append(", ");
             sql.Append("");
             if(d.Week7)
                 sql.Append("1");
             else
                 sql.Append("0");
             sql.Append("");
             sql.Append(")");
             return WFNetLib.ADO.SQLServerOP.NonQuerySQL(sql.ToString());
         }
         public static int Update(ExperimentData d)
         {
             StringBuilder sql=new StringBuilder();
             sql.Append("update Experiment set ");
             sql.Append("Name=");
             sql.Append("'");
             sql.Append(d.Name.ToString());
             sql.Append("'");
             sql.Append(", ");
             sql.Append("Room=");
             sql.Append("'");
             sql.Append(d.Room.ToString());
             sql.Append("'");
             sql.Append(", ");
             sql.Append("Times=");
             sql.Append("'");
             sql.Append(d.Times.ToString());
             sql.Append("'");
             sql.Append(", ");
             sql.Append("Week1=");
             sql.Append("");
             if(d.Week1)
                 sql.Append("1");
             else
                 sql.Append("0");
             sql.Append("");
             sql.Append(", ");
             sql.Append("Week2=");
             sql.Append("");
             if(d.Week2)
                 sql.Append("1");
             else
                 sql.Append("0");
             sql.Append("");
             sql.Append(", ");
             sql.Append("Week3=");
             sql.Append("");
             if(d.Week3)
                 sql.Append("1");
             else
                 sql.Append("0");
             sql.Append("");
             sql.Append(", ");
             sql.Append("Week4=");
             sql.Append("");
             if(d.Week4)
                 sql.Append("1");
             else
                 sql.Append("0");
             sql.Append("");
             sql.Append(", ");
             sql.Append("Week5=");
             sql.Append("");
             if(d.Week5)
                 sql.Append("1");
             else
                 sql.Append("0");
             sql.Append("");
             sql.Append(", ");
             sql.Append("Week6=");
             sql.Append("");
             if(d.Week6)
                 sql.Append("1");
             else
                 sql.Append("0");
             sql.Append("");
             sql.Append(", ");
             sql.Append("Week7=");
             sql.Append("");
             if(d.Week7)
                 sql.Append("1");
             else
                 sql.Append("0");
             sql.Append("");
             sql.Append(" where ID='");
             sql.Append(d.ID.ToString());
             sql.Append("'");
             return WFNetLib.ADO.SQLServerOP.NonQuerySQL(sql.ToString());
         }
         public static int Delete(ExperimentData d)
         {
             StringBuilder sql=new StringBuilder();
             sql.Append("delete from Experiment ");
             sql.Append(" where ID='");
             sql.Append(d.ID.ToString());
             sql.Append("'");
             return WFNetLib.ADO.SQLServerOP.NonQuerySQL(sql.ToString());
         }
         public static DataTable DataTableSelect()
         {
             StringBuilder sql=new StringBuilder();
             sql.Append("select * from Experiment ");
             return WFNetLib.ADO.SQLServerOP.DataTableSQL(sql.ToString());
         }
         public static DataTable DataTableSelect(ExperimentData d)
         {
             StringBuilder sql=new StringBuilder();
             sql.Append("select * from Experiment where ID='");
             sql.Append(d.ID.ToString());
             sql.Append("'");
             return WFNetLib.ADO.SQLServerOP.DataTableSQL(sql.ToString());
         }
         public static DataSet DataSetSelect()
         {
             StringBuilder sql=new StringBuilder();
             sql.Append("select * from Experiment ");
             return WFNetLib.ADO.SQLServerOP.DataSetSQL(sql.ToString());
         }
         public static SqlDataReader ReaderSelect(ExperimentData d)
         {
             StringBuilder sql=new StringBuilder();
             sql.Append("select * from Experiment ");
             return WFNetLib.ADO.SQLServerOP.ReaderExecuteSQL(sql.ToString());
         }
         public static ExperimentData GetExperimentData(Guid id)
         {
             StringBuilder sql = new StringBuilder();
             sql.Append("select * from Experiment where ID='");
             sql.Append(id.ToString());
             sql.Append("'");
             DataTable dt = WFNetLib.ADO.SQLServerOP.DataTableSQL(sql.ToString());
             if (dt.Rows.Count == 0)
                 return null;
             else
             {
                 ExperimentData ed = ExperimentDataFactory.Construct(dt.Rows[0]);
                 return ed;
             }
         }
     }
}
